
import an58 from '@mmstudio/an000058';
import { message } from 'antd';
import api from '../../../atoms/api';
import { Message as M1, Result as R1 } from '../../api/teachgl/del.api';
import Kcbedit from './kcbedit';




export default function Section({ data }: { data: ITbcurriculums; }) {
	console.debug(data);
	if (!data) {
		return <>
			<div>
				<img className='btn' title='新增' onClick={(e) => {
					// todo show add dialog
				}} src='/icons/edit.svg'></img>
			</div>
			<style jsx>{`
div .btn{
width: 2rem;
visibility:hidden;
	cursor: pointer;
}
div:hover .btn{
visibility:visible;
}
`}</style>
		</>;
	}
	return <>
		<div className='s01' onContextMenu={(e) => {
			// 在这里写鼠标右键事件
			e.preventDefault();
		}}>
			<div className='box'>
				<div className='btn' >

				</div>
				<img className='btn' title='删除' onClick={async () => {
					const id = data.course_id;
					const ret = await an58<R1, M1>(api['/api/teachgl/del'], 'delete', {
						id
					});
					if (ret.ok === true) {
						message.success('Success');
						location.reload();
					} else {
						message.error(ret.message);
					}
				}} src='/icons/del.svg'></img>
			</div>
			<div>
				{data.coursename},
				{data.teachername},<br />
				{data.classroom}
				({data.startteachingweek}-{data.endteachingweek})周
			</div>
		</div>
		<style jsx>{`
.box{
	display: flex;
	flex-direction: row;
	position: absolute;
	left: 3rem;
}
.btn{
	width: 1.5rem;
	cursor: pointer;
	margin: 0.5rem;
margin-top: 0rem;
}
.s01 .box {
	display: none;
}
.s01:hover .box {
	display: block;
}
		`}</style>
	</>;
}
